#include "Appointment.h"

Appointment::Appointment(const Appointment & other) {
	start_hour_ = other.getStartHour();
	end_hour_ = other.getEndHour();
	start_min_ = other.getStartMin();
	end_min_ = other.getEndMin();
	subject_ = other.getSubject();
	day_index_ = other.getDayIndex();
}

Appointment & Appointment::operator= (const Appointment & other) {
	if (this != &other) {
		this->start_hour_ = other.getStartHour();
		this->end_hour_ = other.getEndHour();
		this->start_min_ = other.getStartMin();
		this->end_min_ = other.getEndMin();
		this->subject_ = other.getSubject();
		this->day_index_ = other.getDayIndex();
	}

	return *this;
}

void Appointment::updateTime(const int & day_index, const int & start_hour, const int & start_min, const int & end_hour, const int & end_min) {
	day_index_ = day_index;
	start_hour_ = start_hour;
	end_hour_ = end_hour;
	start_min_ = start_min;
	end_min_ = end_min;
}

bool Appointment::operator== (const Appointment & other) const {
	return ((((start_hour_ > other.getStartHour()) || ((start_hour_ == other.getStartHour()) && (start_min_ >= other.getStartMin()))) &&
			 ((start_hour_ < other.getEndHour()) || ((start_hour_ == other.getEndHour()) && (start_min_ < other.getEndMin())))) ||
			 ((other.getStartHour() > start_hour_) || ((other.getStartHour() == start_hour_) && (other.getStartMin() >= start_min_))) &&
			 ((other.getStartHour() < end_hour_) || ((other.getStartHour() == end_hour_) && (other.getStartMin() < end_min_))));
}

bool Appointment::operator< (const Appointment & other) const {
	return (start_hour_ < other.getStartHour() || (start_hour_ == other.getStartHour() && start_min_ < other.getStartMin()));
}

ostream &operator<< (ostream& os, const Appointment & app) {

	os << right << setw(2) << setfill('0') << app.getStartHour() << ":" << setw(2) << setfill('0') << app.getStartMin() << "-" 
				<< setw(2) << setfill('0') << app.getEndHour() << ":" << setw(2) << setfill('0') << app.getEndMin() << " ; Subject: " << app.getSubject();

	return os;
}